#ifndef GL_VALIDATION_HPP
#define GL_VALIDATION_HPP

#include "core/log.h"
#include "glad/glad.h"
#include <memory>

#define UNIQUE_HANDLE(TYPE) \
class TYPE; \
using TYPE##Ptr = std::unique_ptr<TYPE>

#define SHARED_HANDLE(TYPE) \
class TYPE; \
using TYPE##Ptr = std::shared_ptr<TYPE>

#define FACTORY_METHOD(TYPE, ...) \
    static TYPE##Ptr Create(__VA_ARGS__)

extern const char *gl_err_string(GLenum err);

#if !defined(NDEBUG)
#define GLCallValidation(statements)                                                                                               \
    do {                                                                                                                           \
        while (glGetError() != GL_NO_ERROR)                                                                                        \
            ;                                                                                                                      \
        statements;                                                                                                                \
        GLenum error = glGetError();                                                                                               \
        if (error != GL_NO_ERROR) {                                                                                                \
            LOG_E("OpenGL Error with code %s(%d), at %s:%d ==> %s", gl_err_string(error), error, __FILE__, __LINE__, #statements); \
        }                                                                                                                          \
    } while (0)
#else
#define GLCallValidation(statements) \
    do { statements; } while (0)
#endif
#endif// GL_VALIDATION_HPP
